<?php 
 session_start();
function getConn(){
	echo'<meta charset="utf-8">';
	 try {
         //连接数据库 参数四（持久连接）：array(PDO::ATTR_PERSISTENT => true)
         $pdo = new PDO("mysql:host=localhost;port=3306;dbname=blog202",'root','123456');
         //设置字符集
         $pdo->query("set names utf8");
		 return $pdo;
		 
		 }catch (PDOException $ex){
			 exit("不能连接数据库".$ex);
		 }
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$username = $_POST['username'];
$password = $_POST['password'];
$pdo = getConn();
     $sql = "select * from users where username=:username and password=:password";
     
     $stmt = $pdo ->prepare($sql);
     
     $stmt->bindParam(":username",$username);
     $stmt->bindParam(":password",$password);
     $stmt->execute();
     $row = $stmt->fetch();
	 if($row){
	 		 echo"用户名：". $row['username']. " 密码：".$row['password']."</br>";
	 }else{
	 		 echo"该用户不存在";
	 }

if($username=='admin'&& $password=='123456'){
	$_SESSION['username'] =$username;
	echo '登录成功';
		header("Location:./admin/list.php");
}else{
	die('登录失败');
}
}	 
?>
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title></title>
	<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
	
	<!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
	
	<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
	<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

	<style>
		.login-box{
			margin-top:200px;
			padding:50px;
			border-radius: 20px;
			position: relative;
		}
		/* 让每个输入框之间有间距  做法：给login-box的每个子元素div设置外边距 */
		.login-box>div{
			margin-bottom:20px;
		}
		
		.login-box>.into{
			position: absolute;
			background-color: white;
			width:100%;
			height:100%;
			z-index: -1;
			top:-5px;
			left:-5px;
			opacity: 0.7;
			border-radius: 20px;
		}
		
		body{
			background: url(imgs/1.jpg) no-repeat;
			
			/* 让图片铺满整个页面 */
			background-size: cover;    
		}
		html{
			height: 100%;
			/* 隐藏超出部分，去除滚动条 */
			overflow: hidden;
		}
	</style>
</head>
<body>
	<div class="row">
		<form action="" method="post">
	  <!-- col-md-offset-4 表示向右偏移4个格子（前面空4格） -->
	  <div class="col-md-4 col-md-offset-4 login-box">
		  <div class="into"></div>
		  <div class="input-group input-group-lg">
		    <span class="input-group-addon">账号</span>
		    <input type="text" name='username' class="form-control" placeholder="用户名">
		  </div>
		  <div class="input-group input-group-lg">
		    <span class="input-group-addon">密码</span>
		    <input type="text" name="password" class="form-control" placeholder="密码">
		  </div>
		  <div>
		  	<button type="submit" class="form-control btn btn-primary">登录</button>
		  </div>
	  </div>
	</div>
</form>
</body>
</html>
